package com.example.wangyongdong.bearsqlitedemo.oilwear;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.wangyongdong.bearsqlitedemo.R;

/**
 * Created by wangyongdong on 2017/4/21.
 */

public class OilWearFragment extends Fragment{
    private ImageView pointIv1,pointIv2,pointIv3,pointIv4,pointIv5,leftIv,rightIv;
    private LinearLayout linearLayout;
    private int count = 0;
    private TextView wearTv;

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        leftIv = (ImageView) view.findViewById(R.id.oilwear_left_iv);
        rightIv = (ImageView) view.findViewById(R.id.oilwear_right_iv);
        linearLayout = (LinearLayout) view.findViewById(R.id.point_ly);
        wearTv = (TextView) view.findViewById(R.id.oilwear_tv);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return LayoutInflater.from(getContext()).inflate(R.layout.fragment_oilwear,container,false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        for (int i = 0; i < 5; i++) {
            pointIv1 = new ImageView(getContext());
            pointIv1.setPadding(0,0,0,0);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(80,80);
            pointIv1.setLayoutParams(params);
            if (i == 0){
                pointIv1.setImageResource(R.mipmap.point_white);
            }else {
                pointIv1.setImageResource(R.mipmap.point_grey);
            }
            linearLayout.addView(pointIv1);
        }

        rightIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (count){
                    case 0:
                        count = 1;
                        wearTv.setText("最近一年油耗统计曲线");
                        linearLayout.removeAllViewsInLayout();
                        for (int i = 0; i < 5; i++) {
                            pointIv2 = new ImageView(getContext());
                            pointIv2.setPadding(0,0,0,0);
                            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(80,80);
                            pointIv2.setLayoutParams(params);
                            if (i == 1){
                                pointIv2.setImageResource(R.mipmap.point_white);
                            }else {
                                pointIv2.setImageResource(R.mipmap.point_grey);
                            }
                            linearLayout.addView(pointIv2);
                        }
                        break;
                    case 1:
                        count = 2;
                        wearTv.setText("最近半年油耗统计曲线");
                        linearLayout.removeAllViewsInLayout();
                        for (int i = 0; i < 5; i++) {
                            pointIv3 = new ImageView(getContext());
                            pointIv3.setPadding(0,0,0,0);
                            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(80,80);
                            pointIv3.setLayoutParams(params);
                            if (i == 2){
                                pointIv3.setImageResource(R.mipmap.point_white);
                            }else {
                                pointIv3.setImageResource(R.mipmap.point_grey);
                            }
                            linearLayout.addView(pointIv3);
                        }
                        break;
                    case 2:
                        count = 3;
                        wearTv.setText("最近三个月油耗统计曲线");
                        linearLayout.removeAllViewsInLayout();
                        for (int i = 0; i < 5; i++) {
                            pointIv4 = new ImageView(getContext());
                            pointIv4.setPadding(0,0,0,0);
                            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(80,80);
                            pointIv4.setLayoutParams(params);
                            if (i == 3){
                                pointIv4.setImageResource(R.mipmap.point_white);
                            }else {
                                pointIv4.setImageResource(R.mipmap.point_grey);
                            }
                            linearLayout.addView(pointIv4);
                        }
                        break;
                    case 3:
                        count = 4;
                        wearTv.setText("同城车型油耗基准线");
                        linearLayout.removeAllViewsInLayout();
                        for (int i = 0; i < 5; i++) {
                            pointIv5 = new ImageView(getContext());
                            pointIv5.setPadding(0,0,0,0);
                            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(80,80);
                            pointIv5.setLayoutParams(params);
                            if (i == 4){
                                pointIv5.setImageResource(R.mipmap.point_white);
                            }else {
                                pointIv5.setImageResource(R.mipmap.point_grey);
                            }
                            linearLayout.addView(pointIv5);
                        }
                        break;
                    case 4:
                        count = 0;
                        wearTv.setText("油耗统计曲线");
                        linearLayout.removeAllViewsInLayout();
                        for (int i = 0; i < 5; i++) {
                            pointIv1 = new ImageView(getContext());
                            pointIv1.setPadding(0,0,0,0);
                            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(80,80);
                            pointIv1.setLayoutParams(params);
                            if (i == 0){
                                pointIv1.setImageResource(R.mipmap.point_white);
                            }else {
                                pointIv1.setImageResource(R.mipmap.point_grey);
                            }
                            linearLayout.addView(pointIv1);
                        }
                        break;
                }
            }
        });

        leftIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (count){
                    case 0:
                        count = 4;
                        wearTv.setText("同城车型油耗基准线");
                        linearLayout.removeAllViewsInLayout();
                        for (int i = 0; i < 5; i++) {
                            pointIv5 = new ImageView(getContext());
                            pointIv5.setPadding(0,0,0,0);
                            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(80,80);
                            pointIv5.setLayoutParams(params);
                            if (i == 4){
                                pointIv5.setImageResource(R.mipmap.point_white);
                            }else {
                                pointIv5.setImageResource(R.mipmap.point_grey);
                            }
                            linearLayout.addView(pointIv5);
                        }
                        break;
                    case 4:
                        count = 3;
                        wearTv.setText("最近三个月油耗统计曲线");
                        linearLayout.removeAllViewsInLayout();
                        for (int i = 0; i < 5; i++) {
                            pointIv4 = new ImageView(getContext());
                            pointIv4.setPadding(0,0,0,0);
                            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(80,80);
                            pointIv4.setLayoutParams(params);
                            if (i == 3){
                                pointIv4.setImageResource(R.mipmap.point_white);
                            }else {
                                pointIv4.setImageResource(R.mipmap.point_grey);
                            }
                            linearLayout.addView(pointIv4);
                        }
                        break;
                    case 3:
                        count = 2;
                        wearTv.setText("最近半年油耗统计曲线");
                        linearLayout.removeAllViewsInLayout();
                        for (int i = 0; i < 5; i++) {
                            pointIv3 = new ImageView(getContext());
                            pointIv3.setPadding(0,0,0,0);
                            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(80,80);
                            pointIv3.setLayoutParams(params);
                            if (i == 2){
                                pointIv3.setImageResource(R.mipmap.point_white);
                            }else {
                                pointIv3.setImageResource(R.mipmap.point_grey);
                            }
                            linearLayout.addView(pointIv3);
                        }
                        break;
                    case 2:
                        count = 1;
                        wearTv.setText("最近一年油耗统计曲线");
                        linearLayout.removeAllViewsInLayout();
                        for (int i = 0; i < 5; i++) {
                            pointIv2 = new ImageView(getContext());
                            pointIv2.setPadding(0,0,0,0);
                            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(80,80);
                            pointIv2.setLayoutParams(params);
                            if (i == 1) {
                                pointIv2.setImageResource(R.mipmap.point_white);
                            }else {
                                pointIv2.setImageResource(R.mipmap.point_grey);
                            }
                            linearLayout.addView(pointIv2);
                        }
                        break;
                    case 1:
                        count = 0;
                        wearTv.setText("油耗统计曲线");
                        linearLayout.removeAllViewsInLayout();
                        for (int i = 0; i < 5; i++) {
                            pointIv1 = new ImageView(getContext());
                            pointIv1.setPadding(0,0,0,0);
                            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(80,80);
                            pointIv1.setLayoutParams(params);
                            if (i == 0){
                                pointIv1.setImageResource(R.mipmap.point_white);
                            }else {
                                pointIv1.setImageResource(R.mipmap.point_grey);
                            }
                            linearLayout.addView(pointIv1);
                        }
                        break;
                }
            }
        });
    }
}
